#!/usr/bin/env python3
"""
修复 wechat_dialog_extractor.py 中的 GPU 设置
"""
import os
import re

# 要修改的文件路径
file_paths = [
    'ocr_python/wechat_dialog_extractor.py',
    'demo/ocr_python/wechat_dialog_extractor.py'
]

for file_path in file_paths:
    if not os.path.exists(file_path):
        print(f"文件 {file_path} 不存在，跳过")
        continue
        
    # 读取文件内容
    with open(file_path, 'r', encoding='utf-8') as f:
        content = f.read()
    
    # 替换 GPU 设置
    modified_content = re.sub(
        r'reader = easyocr\.Reader\(\[\'ch_sim\', \'en\'\], gpu=True\)',
        r'reader = easyocr.Reader([\'ch_sim\', \'en\'], gpu=False)',
        content
    )
    
    # 写回文件
    with open(file_path, 'w', encoding='utf-8') as f:
        f.write(modified_content)
    
    print(f"已成功修改 {file_path} 中的 GPU 设置为 False")
